import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

import junit.framework.TestCase;

/**
 * To test the Radix Sorter class
 * @author Matthew Dye
 *
 * @param <K>
 */
public class MSDRadixSorterTest extends TestCase {
	Scanner scan;
	ArrayList<String> keys;
	ArrayList<Integer> vals;
	MSDRadixSorter<Integer> rs;
	HashNode<String,Integer>[] arr, arr2;
	public void testAdd() throws FileNotFoundException
	{
		scan = new Scanner(new File("names.txt"));
		vals = new ArrayList<Integer>();
		keys = new ArrayList<String>();
		rs = new MSDRadixSorter<Integer>();
		arr = (HashNode<String,Integer>[])new HashNode[10];
		for (int i = 0; i < 10; i++){
			keys.add(scan.next());
		}

		scan = new Scanner(new File("primeslist.txt"));
		for (int i = 0; i < 10; i++){
			vals.add(Integer.parseInt(scan.next()));
		}
		for (int i = 0; i < 10; i++){
			arr[i] = new HashNode<String,Integer>(keys.get(i), vals.get(i));
		}
		arr2 = rs.sort(arr);
		assertFalse(rs.contains("MATT", arr2));
		arr2 = rs.add("MATT",315,arr2);
		assertTrue(rs.contains("MATT", arr2));
	}
	
	public void testRemoveDuplicates() throws FileNotFoundException
	{
		scan = new Scanner(new File("names.txt"));
		vals = new ArrayList<Integer>();
		keys = new ArrayList<String>();
		rs = new MSDRadixSorter<Integer>();
		arr = (HashNode<String,Integer>[])new HashNode[10];
		for (int i = 0; i < 10; i++){
			keys.add(scan.next());
		}

		scan = new Scanner(new File("primeslist.txt"));
		for (int i = 0; i < 10; i++){
			vals.add(Integer.parseInt(scan.next()));
		}
		for (int i = 0; i < 10; i++){
			arr[i] = new HashNode<String,Integer>(keys.get(i), vals.get(i));
		}
		arr2 = rs.sort(arr);
		assertFalse(rs.contains("MATT", arr2));
		arr2 = rs.add("MATT",315,arr2);
		arr2 = rs.add("MATT",315,arr2);
		arr2 = rs.add("MATT",315,arr2);
		arr2 = rs.removeDuplicates(arr2);
		assertTrue(rs.contains("MATT", arr2));
		assertTrue(arr2.length==11);
	}
	public void testGet() throws FileNotFoundException
	{
		scan = new Scanner(new File("names.txt"));
		vals = new ArrayList<Integer>();
		keys = new ArrayList<String>();
		rs = new MSDRadixSorter<Integer>();
		arr = (HashNode<String,Integer>[])new HashNode[10];
		for (int i = 0; i < 10; i++){
			keys.add(scan.next());
		}

		scan = new Scanner(new File("primeslist.txt"));
		for (int i = 0; i < 10; i++){
			vals.add(Integer.parseInt(scan.next()));
		}
		for (int i = 0; i < 10; i++){
			arr[i] = new HashNode<String,Integer>(keys.get(i), vals.get(i));
		}
		arr2 = rs.sort(arr);
		arr2 = rs.add("MATT",315,arr2);
		int val = rs.get("MATT", arr2);
		assertTrue(val==315);
	}

}
